package util;

import com.t2tierp.pafecf.bd.AcessoBanco;
import java.sql.Connection;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import javax.swing.JOptionPane;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperPrintManager;
import net.sf.jasperreports.view.JasperViewer;

/**
 *
 * @author gilberto.costa 02/01/2012 14:04
 */
public class Relatorios {

    private static AcessoBanco ace = new AcessoBanco();
    private static Connection con = ace.conectar();

    public static void geraRelatorioDAV(String opcao, Integer idDAV) {
        JasperPrint rel = null;
        try {
            Map map = new HashMap();
            map.put("ID_DAV", idDAV.toString());
            String arquivoJasper = CaminhoPathJasper() + "\\Relatorios\\DAV.jasper";
            rel = JasperFillManager.fillReport(arquivoJasper, map, con);
            if (opcao.equalsIgnoreCase("imprimir")) {
                JasperPrintManager.printReport(rel, true);
            } else {
                JasperViewer.viewReport(rel, false);
            }
        } catch (JRException e) {
            JOptionPane.showMessageDialog(null, "Erro ao gerar relatorio de estoque minimo: " + e);
        }
    }

    public static void geraRelatorioDetalhadoEntreDatas(String opcao, Date dataInicio, Date dataFinal) {
        JasperPrint rel = null;
        try {
            Map map = new HashMap();
            map.put("Data_Inicio", dataInicio);
            map.put("Data_Fim", dataFinal);
            String arquivoJasper = CaminhoPathJasper() + "/DAV.jasper";
            rel = JasperFillManager.fillReport(arquivoJasper, map, con);
            if (opcao.equalsIgnoreCase("imprimir")) {
                JasperPrintManager.printReport(rel, true);
            } else {
                JasperViewer.viewReport(rel, false);
            }
        } catch (JRException e) {
            JOptionPane.showMessageDialog(null, "Erro ao gerar relatorio : " + e);
        }
    }

    public static String CaminhoPathJasper() {
        String caminho = System.getProperty("user.dir");//caminho onde a aplicação estiver
        return caminho;
    }
}